// pages/my/my.js
import { ClassicModel } from '../../models/classic'
import { BookModel } from '../../models/book'
const classicModel = new ClassicModel()
const bookModel = new BookModel()

Page({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    authorized: false,
    userInfo: '',
    bookCount: 0,
    classics: null
  },
  onShow() {
    this.userAutorized()
    this.getMyBookCount()
    this.getMyFavor()
  },
  getMyFavor(){
    classicModel.getMyFavor(res=>{
      this.setData({
      classics: res.data
      })
    })
  },
  getMyBookCount() {
    bookModel.getMyBookCount().then(res => {
      this.setData({
        bookCount: res.count
      })
    })
  },
  onGetUserInfo(event) {
    const userInfo = event.detail.userInfo
    this.setData({
      userInfo,
      authorized: true,
    })
  },
  userAutorized() {
    wx.getUserInfo({
      success: res => {
        this.setData({
          authorized: true,
          userInfo: res.userInfo
        })
      },
      fail: error => {
        console.log(error)
      }
    })
  },
  onJumpToAbout() {
    wx.navigateTo({
      url: '/pages/about/about'
    })
  },
  onStudy() {
    wx.navigateTo({
      url: '/pages/course/course'
    })
  }
})